package com.xiaoxu.entry.bishi;

import java.util.Arrays;

public class MergeArray {
    public static void main(String[] args) {
        int[] a = {1,4,5,0,0,0};
        int[] b = {2,5,6};
        int m = 3;
        int n = 3;
        merge(a,m,b,n);
        System.out.println(Arrays.toString(a));
    }

    public static void merge(int[] nums1,int m,int[] nums2,int n){
        int p1 = m - 1;
        int p2 = n - 1;
        int p = m + n - 1;

        while (p1 >=0 && p2 >= 0){
            nums1[p--] = nums1[p1] < nums2[p2] ? nums2[p2--] : nums1[p1--];
        }
        System.arraycopy(nums2,0,nums1,0,p2+1);
    }
}
